package ut.servlet.member;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
public class Contact extends HttpServlet{
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		// 取得並驗證使用者輸入資訊
		String subject, content;
		if(request.getParameter("subject") == null || request.getParameter("content") == null){
			return;
		}else{
			subject = request.getParameter("subject").replace("&", "&amp;").replace("\"", "&quot;").replace("<", "&lt;").replace(">", "&gt;");
			content = request.getParameter("content").replace("&", "&amp;").replace("\"", "&quot;").replace("<", "&lt;").replace(">", "&gt;");
			content = content.replace("\r\n", "<br/>").replace("\n", "<br/>").replace("\r", "<br/>");
		}
		// 取得使用者資料
		ut.data.User user = (ut.data.User)request.getSession().getAttribute("user");
		// 寄送郵件
		response.setHeader("result", ut.service.Mail.sendContactEmail(user, subject, content) + ""); // true: 成功, false: 失敗
	}
}